// components/task/index.js
const app = getApp()

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    checked: Boolean,
    lemon: Object
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleToggle: function () {
      const { index, isDone, listId } = this.data.lemon
      const payload = {
        index,
        listId: listId || app.state.cid,
        isDone: !isDone
      }
      this.triggerEvent('toggledone', payload)
    },
    handleLongpress: function () {
      const _this = this
      const { index, isDone, today, listId, todo } = this.data.lemon
      const payload = {
        index,
        listId: listId || app.state.cid
      }

      const itemList = []
      itemList.push(today ? '从"我的一天"中删除' : '添加到"我的一天"')
      itemList.push(isDone ? '标记未完成' : '标记已完成')
      itemList.push('删除')

      wx.showActionSheet({
        itemList,
        success: function ({ tapIndex }) {
          if (tapIndex === 0) {
            payload.today = !today
            _this.triggerEvent('toggletoday', payload)
          } else if (tapIndex === 1) {
            payload.isDone = !isDone
            _this.triggerEvent('toggledone', payload)
          } else if (tapIndex === 2) {
            payload.todo = todo
            _this.triggerEvent('delete', payload)
          }
        }
      })
    }
  }
})
